home *** CD-ROM | disk | FTP | other *** search
- /* convert.c */
-
- /* this program converts an off geometry file (.geom) to an .obj file
- (used by radiosity package) */
- /* written by : Jason R. Wilson */
- /* last modified : 2/21/93 */
-
- #include <stdio.h>
-
- main ()
-
- {
-
- int NumVerts;
- int NumPolys;
- FILE *inputfp;
- FILE *outputfp;
- int loop,loop2;
- float x,y,z;
- int numvertsneeded;
- int a,b,c,d;
- char infilename[256];
- char outfilename[256];
- char answer[256];
- double Er,Eg,Eb,Rr,Rg,Rb;
- int clockwise;
-
- /* get input from user */
- printf ("Please enter the name of the input file (.geom)\n");
- scanf ("%s",infilename);
- printf ("Please enter the name of the output file (.obj)\n");
- scanf ("%s",outfilename);
-
- inputfp = fopen (infilename,"r"); /* open input data file */
- outputfp = fopen (outfilename,"w"); /* open output data file */
-
- printf ("Is the data in the input file stored clockwise? (y or n)\n");
- scanf ("%s",answer);
-
- if ((answer[0] == 'y') || (answer[0] == 'Y'))
- clockwise = 1;
- else
- clockwise = 0;
-
- printf ("Please enter the emission values for the output file\n");
- scanf ("%lf %lf %lf",&Er,&Eg,&Eb);
- printf ("Please enter the reflectivity values for the output file\n");
- scanf ("%lf %lf %lf",&Rr,&Rg,&Rb);
- printf ("Thank you--converting ...\n");
-
- /* convert file */
- fscanf (inputfp,"%d %d %d",&NumVerts,&NumPolys,&loop);
- fprintf (outputfp,"%d\n",NumVerts);
- fprintf (outputfp,"%d\n",NumPolys);
- fprintf (outputfp,"\n");
-
- for (loop = 0;loop < NumVerts;loop++)
- {
- fscanf (inputfp,"%f %f %f",&x,&y,&z);
- fprintf (outputfp,"%f %f %f\n",x,y,z);
- }
-
- fprintf (outputfp,"\n");
-
- for (loop = 0;loop < NumPolys;loop++)
- {
- fscanf (inputfp,"%d",&numvertsneeded);
- if (numvertsneeded == 3)
- {
- fscanf (inputfp,"%d %d %d",&a,&b,&c);
- if (clockwise == 1)
- fprintf (outputfp,"3 %d %d %d\n",c,b,a);
- else
- fprintf (outputfp,"3 %d %d %d\n",a,b,c);
- fprintf (outputfp,"0 %lf %lf %lf %lf %lf %lf\n\n",Er,Eg,Eb,Rr,Rg,Rb);
- }
- else
- {
- fscanf (inputfp,"%d %d %d %d",&a,&b,&c,&d);
- if (clockwise == 1)
- fprintf (outputfp,"4 %d %d %d %d\n",d,c,b,a);
- else
- fprintf (outputfp,"4 %d %d %d %d\n",a,b,c,d);
- fprintf (outputfp,"0 %lf %lf %lf %lf %lf %lf\n\n",Er,Eg,Eb,Rr,Rg,Rb);
- }
-
- }
- close (inputfp);
- close (outputfp);
- }
-
-
-